﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

///<summary>
///EnemyAttckState
///</summary>
public class EnemyAttckState:IEnemyState
{
    /// <summary>
    /// 攻击间隔
    /// </summary>
    private float mAttackTime = 1;

    private float mAttackTimer = 1;

    public EnemyAttckState(EnemyFSMSystem fsm, ICharacter character) : base(fsm, character)
    {
        mStateID = EnemyStateID.Attack;
        mAttackTimer = mAttackTime;
    }

    public override void Reason(List<ICharacter> targets)
    {
        if (targets == null || targets.Count == 0)
        {
            mFsm.PerformTransition(EnemyTransition.LostSoldier);
        }
        else
        {
            float distance = Vector3.Distance(mCharacter.Position, targets[0].Position);
            if (distance > mCharacter.atkRange)
            {
                mFsm.PerformTransition(EnemyTransition.LostSoldier);
            }
        }
    }

    public override void Act(List<ICharacter> targets)
    {
        if (targets == null || targets.Count == 0) return;
        //攻击 通过计时器1S一次
        mAttackTimer += Time.deltaTime;
        if (mAttackTimer>=mAttackTime)
        {
            mCharacter.Attack(targets[0]);
            mAttackTimer = 0;
        }
    }
}

